package com.lzh.runke.util;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
 * @author LiuZiHao
 * @date 创建时间:2023年05月04日 17:01:37
 */
public class Base64Util {
    private final static Base64.Encoder ENCODER = Base64.getEncoder();
    private final static Base64.Decoder DECODER = Base64.getDecoder();

    public static String encode(String text) {
        return ENCODER.encodeToString(text.getBytes(StandardCharsets.UTF_8));
    }

    public static String encode(byte[] bytes) {
        return ENCODER.encodeToString(bytes);
    }

    public static String decode(String encodedText) {
        return new String(DECODER.decode(encodedText), StandardCharsets.UTF_8);
    }

    public static void main(String[] args) {
        String str = "test123";
        System.out.println(Base64Util.encode(str));
        System.out.println(Base64Util.decode(Base64Util.encode(str)));
    }

}
